import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';
import LanguageDetector from 'i18next-browser-languagedetector';

// 中文翻译
const zhCN = {
    translation: {
        // 通用
        common: {
            add: '添加',
            edit: '编辑',
            delete: '删除',
            save: '保存',
            cancel: '取消',
            confirm: '确认',
            search: '搜索',
            reset: '重置',
            submit: '提交',
            loading: '加载中...',
            success: '操作成功',
            error: '操作失败',
            warning: '警告',
            info: '提示',
            yes: '是',
            no: '否',
            total: '共',
            page: '页',
            items: '条',
        },

        // 导航菜单
        menu: {
            dashboard: '仪表盘',
            sampleManagement: '样地管理',
            deviceManagement: '设备管理',
            dataQuery: '数据查询',
            settings: '系统设置',
        },

        // 样地管理
        sample: {
            title: '样地管理',
            addSample: '添加样地',
            editSample: '编辑样地',
            sampleCode: '样地编号',
            sampleName: '样地名称',
            longitude: '经度',
            latitude: '纬度',
            createTime: '创建时间',
            operation: '操作',
            deleteConfirm: '确定要删除这个样地吗？',
            addSuccess: '样地信息添加成功',
            editSuccess: '样地信息修改成功',
            deleteSuccess: '样地删除成功',
            addFailed: '添加样地信息失败',
            editFailed: '修改样地信息失败',
            deleteFailed: '删除样地失败',
            fetchFailed: '获取样地列表失败',
        },

        // 设备管理
        device: {
            title: '设备管理',
            addDevice: '添加设备',
            editDevice: '编辑设备',
            sampleCode: '样地编号',
            deviceType: '设备类型',
            batchNumber: '设备批次号',
            deviceCode: '设备编号',
            macAddress: 'MAC地址',
            createTime: '创建时间',
            operation: '操作',
            deviceTypes: {
                normal: '普通',
                g4: '4G',
                gateway: '网关',
            },
            deleteConfirm: '确定要删除这个设备吗？',
            addSuccess: '设备信息添加成功',
            editSuccess: '设备信息修改成功',
            deleteSuccess: '设备删除成功',
            addFailed: '添加设备信息失败',
            editFailed: '修改设备信息失败',
            deleteFailed: '删除设备失败',
            fetchFailed: '获取设备列表失败',
        },

        // 数据查询
        data: {
            title: '数据查询',
            deviceData: '设备数据',
            temperatureHumidity: '温湿度数据',
            deviceParams: '设备参数',
            sampleCode: '样地编号',
            gatewayBatch: '网关设备批次号',
            gatewayCode: '网关设备编号',
            batchNumber: '设备批次号',
            deviceCode: '设备编号',
            startTime: '起始时间',
            endTime: '结束时间',
            voltage: '电压',
            measureValue: '测量值',
            angle: '角度',
            chipTemperature: '芯片温度',
            signalStrength: '信号强度',
            longitude: '经度',
            latitude: '纬度',
            temperature: '温度',
            humidity: '湿度',
            fetchFailed: '获取数据失败',
        },

        // 系统设置
        settings: {
            title: '系统设置',
            theme: '主题设置',
            language: '语言设置',
            layout: '布局设置',
            lightTheme: '浅色主题',
            darkTheme: '深色主题',
            chinese: '中文',
            english: 'English',
            sidebarCollapsed: '侧边栏收起',
            sidebarExpanded: '侧边栏展开',
        },
    },
};

// 英文翻译
const enUS = {
    translation: {
        // Common
        common: {
            add: 'Add',
            edit: 'Edit',
            delete: 'Delete',
            save: 'Save',
            cancel: 'Cancel',
            confirm: 'Confirm',
            search: 'Search',
            reset: 'Reset',
            submit: 'Submit',
            loading: 'Loading...',
            success: 'Operation successful',
            error: 'Operation failed',
            warning: 'Warning',
            info: 'Info',
            yes: 'Yes',
            no: 'No',
            total: 'Total',
            page: 'Page',
            items: 'items',
        },

        // Navigation menu
        menu: {
            dashboard: 'Dashboard',
            sampleManagement: 'Sample Management',
            deviceManagement: 'Device Management',
            dataQuery: 'Data Query',
            settings: 'Settings',
        },

        // Sample management
        sample: {
            title: 'Sample Management',
            addSample: 'Add Sample',
            editSample: 'Edit Sample',
            sampleCode: 'Sample Code',
            sampleName: 'Sample Name',
            longitude: 'Longitude',
            latitude: 'Latitude',
            createTime: 'Create Time',
            operation: 'Operation',
            deleteConfirm: 'Are you sure to delete this sample?',
            addSuccess: 'Sample added successfully',
            editSuccess: 'Sample updated successfully',
            deleteSuccess: 'Sample deleted successfully',
            addFailed: 'Failed to add sample',
            editFailed: 'Failed to update sample',
            deleteFailed: 'Failed to delete sample',
            fetchFailed: 'Failed to fetch sample list',
        },

        // Device management
        device: {
            title: 'Device Management',
            addDevice: 'Add Device',
            editDevice: 'Edit Device',
            sampleCode: 'Sample Code',
            deviceType: 'Device Type',
            batchNumber: 'Batch Number',
            deviceCode: 'Device Code',
            macAddress: 'MAC Address',
            createTime: 'Create Time',
            operation: 'Operation',
            deviceTypes: {
                normal: 'Normal',
                g4: '4G',
                gateway: 'Gateway',
            },
            deleteConfirm: 'Are you sure to delete this device?',
            addSuccess: 'Device added successfully',
            editSuccess: 'Device updated successfully',
            deleteSuccess: 'Device deleted successfully',
            addFailed: 'Failed to add device',
            editFailed: 'Failed to update device',
            deleteFailed: 'Failed to delete device',
            fetchFailed: 'Failed to fetch device list',
        },

        // Data query
        data: {
            title: 'Data Query',
            deviceData: 'Device Data',
            temperatureHumidity: 'Temperature & Humidity',
            deviceParams: 'Device Parameters',
            sampleCode: 'Sample Code',
            gatewayBatch: 'Gateway Batch',
            gatewayCode: 'Gateway Code',
            batchNumber: 'Batch Number',
            deviceCode: 'Device Code',
            startTime: 'Start Time',
            endTime: 'End Time',
            voltage: 'Voltage',
            measureValue: 'Measure Value',
            angle: 'Angle',
            chipTemperature: 'Chip Temperature',
            signalStrength: 'Signal Strength',
            longitude: 'Longitude',
            latitude: 'Latitude',
            temperature: 'Temperature',
            humidity: 'Humidity',
            fetchFailed: 'Failed to fetch data',
        },

        // System settings
        settings: {
            title: 'System Settings',
            theme: 'Theme Settings',
            language: 'Language Settings',
            layout: 'Layout Settings',
            lightTheme: 'Light Theme',
            darkTheme: 'Dark Theme',
            chinese: '中文',
            english: 'English',
            sidebarCollapsed: 'Collapse Sidebar',
            sidebarExpanded: 'Expand Sidebar',
        },
    },
};

i18n
    .use(LanguageDetector)
    .use(initReactI18next)
    .init({
        resources: {
            'zh-CN': zhCN,
            'en-US': enUS,
        },
        fallbackLng: 'zh-CN',
        debug: false,

        interpolation: {
            escapeValue: false,
        },

        detection: {
            order: ['localStorage', 'navigator', 'htmlTag'],
            caches: ['localStorage'],
        },
    });

export default i18n;
